using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Xml;

namespace FanDongping.Stock
{
    public class StockData
    {
        #region privates


        private static TradeHistory tradeHistory;
        private static TradeConfig tradeConfig;

        private static StockList stockList;

        public static StockList StockList
        {
            get
            {
                if (stockList == null)
                {
                    stockList = StockList.Load();
                }

                return StockData.stockList;
            }
            //set { StockData.stockList = value; }
        }

        #endregion  // privates

        #region  members

        [XmlIgnore]
        public static bool Modified
        {
            get
            {
                bool b = false;
                b |= TradeConfig.Modified;
                b |= TradeHistory.Modified;
                b |= StockList.Modified;

                return b;
            }
            set
            {
                tradeConfig.Modified = value;
                tradeHistory.Modified = value;

            }
        }

        public static TradeHistory TradeHistory
        {
            get
            {
                if (tradeHistory == null)
                {
                    tradeHistory = TradeHistory.Load();

                }

                return tradeHistory;
            }
            //set { tradeHistory = value; }
        }

        public static TradeConfig TradeConfig
        {
            get
            {
                if (tradeConfig == null)
                {
                    tradeConfig = TradeConfig.Load();
                }
                return tradeConfig;
            }
            set { tradeConfig = value; }
        }

        #endregion //members


        public static void Save()
        {
            if (stockList != null && stockList.Modified)
            {
                stockList.Save();
            }


            if (tradeConfig != null && tradeConfig.Modified)
            {
                tradeConfig.Save();
            }

            if (tradeHistory != null && tradeHistory.Modified)
            {
                tradeHistory.Save();
            }
        }
    }
}
